﻿using SmartCMS.UI.Helper;
using SmartCMS.UI.SystemManage;
using SmartCMS.UI.ViewModels;
using SmartControls.Controls;
using SmartControls.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WinFormsUI.Docking;

namespace SmartCMS.UI
{
    public partial class MainForm : DockContent
    {
        public MainForm()
        {
            InitializeComponent();
            AutoScaleMode = AutoScaleMode.Dpi;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            SetSchema(this.vS2015BlueToolStripMenuItem, null);
            SystemMenus menu = new SystemMenus();
            dockPanel.DockLeftPortion = 0.15;
            dockPanel.Height = 900;
            menu.Text = "系统菜单";
            menu.Show(dockPanel, DockState.DockLeft);         
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
        }
        private void SetSchema(object sender, System.EventArgs e)
        {
            if (sender == this.vS2015BlueToolStripMenuItem)
            {
                this.dockPanel.Theme = this.vS2015BlueTheme;
                this.EnableVSRenderer(VisualStudioToolStripExtender.VsVersion.Vs2015, vS2015BlueTheme);
            }
            else if (sender == this.vS2015LightToolStripMenuItem)
            {
                this.dockPanel.Theme = this.vS2015BlueTheme;
                this.EnableVSRenderer(VisualStudioToolStripExtender.VsVersion.Vs2015, vS2015BlueTheme);
            }
            else if (sender == this.aVS2015DarkToolStripMenuItem)
            {
                this.dockPanel.Theme = this.vS2015BlueTheme;
                this.EnableVSRenderer(VisualStudioToolStripExtender.VsVersion.Vs2015, vS2015BlueTheme);
            }

            vS2015LightToolStripMenuItem.Checked = (sender == vS2015LightToolStripMenuItem);
            vS2015BlueToolStripMenuItem.Checked = (sender == vS2015BlueToolStripMenuItem);
            aVS2015DarkToolStripMenuItem.Checked = (sender == aVS2015DarkToolStripMenuItem);
            if (dockPanel.Theme.ColorPalette != null)
            {
                MainStatusStrip.BackColor = dockPanel.Theme.ColorPalette.MainWindowStatusBarDefault.Background;
            }


        }
        private void EnableVSRenderer(VisualStudioToolStripExtender.VsVersion version, ThemeBase theme)
        {
            vsToolStripExtender.SetStyle(MainMenus, version, theme);
            vsToolStripExtender.SetStyle(MainTools, version, theme);
            vsToolStripExtender.SetStyle(MainStatusStrip, version, theme);
        }
        private void MainMenus_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
        private DummyDoc CreateNewDocument(string text)
        {
            DummyDoc dummyDoc = new DummyDoc();
            dummyDoc.Text = text;
            return dummyDoc;
        }

        private void HelpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //MenusForm f1 = new MenusForm();
            //f1.Text = "测试标题1";
            //f1.Show(dockPanel, DockState.Document);
            //UserInfoForm win = new UserInfoForm();
            UserListForm win = new UserListForm();
            win.Show(dockPanel, DockState.Document);
        }
        /// <summary>
        /// 密码修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateUPWDBtn_Click(object sender, EventArgs e)
        {
            FrmInputs frm = new FrmInputs("密码修改",
               new string[] { "用户名", "密码", "确认密码" },
               new Dictionary<string, SmartControls.TextInputType>() { { "电话", SmartControls.TextInputType.Regex }, { "密码", SmartControls.TextInputType.Regex }, { "确认密码", SmartControls.TextInputType.Regex } },
               new Dictionary<string, string>() {
                  // { "电话", "^1\\d{10}$" },
                   //{ "身份证号", "^\\d{18}$" }
               },
               new Dictionary<string, KeyBoardType>() {
                   //{ "电话", KeyBoardType.UCKeyBorderNum },
                   //{ "身份证号", KeyBoardType.UCKeyBorderNum }
               },
               new List<string>() { "用户名", "密码", "确认密码" });
            frm.ShowDialog(this);
        }

        private void AboutBtn_Click(object sender, EventArgs e)
        {
            MenusForm win = new MenusForm();
            win.Show(dockPanel, DockState.Document);
        }
        #region 菜单点击事件
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //if (FindDocument("系统菜单") == null)
            //{
            //    SystemMenus menu = new SystemMenus();
            //    dockPanel.DockLeftPortion = 0.15;
            //    menu.Text = "系统菜单";
            //    menu.Show(dockPanel, DockState.DockLeft);
            //}   
            EditMenuForm win = new EditMenuForm();
            win.ShowDialog();
        }

        /// 在dockPanel中查找已经打开的窗口
        /// </summary>
        /// <param name="text">传入的窗口标题</param>
        /// <returns>返回的窗口</returns>
        private IDockContent FindDocument(string text)
        {
            if (dockPanel.DocumentStyle == DocumentStyle.DockingMdi)
            {
                foreach (Form form in MdiChildren)
                    if (form.Text == text)
                        return form as IDockContent;

                return null;
            }
            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                foreach (Form form in MdiChildren)
                    if (form.Text == text)
                        return form as IDockContent;

                return null;
            }
            else
            {
                foreach (IDockContent content in dockPanel.Documents)
                    if (content.DockHandler.TabText == text)
                        return content;

                return null;
            }
        }
        #endregion      
    }
}
